import { Http } from "../../utils/http"
import { Order } from "../../model/Order"

Page({

  data: {
    recordList: [],
    cardList:[]
  },

  //生命周期函数--监听页面加载
  onLoad: async function (options) {
    this.getOrder();
    this.getCard();
  },

  //获取自己核销的订单列表-卡
  getCard: async function () {
    let result = await Order.get_verify_order_by_user_card(1,100);
    if (result.code == 0) {
      this.setData({
        cardList: result.data.data
      })
      // wx.setStorageSync('recordList',result.data.data)
    } else {
      wx.showToast({
        title: result.msg,
        duration: 2000,
        icon: 'none'
      });
    }
  },

  //获取自己核销的订单列表
  getOrder: async function () {
    let result = await Order.get_verify_order_by_user(1,100);
    console.log(result);
    if (result.code == 0) {
      this.setData({
        recordList: result.data.data
      })
      // wx.setStorageSync('recordList',result.data.data)
    } else {
      wx.showToast({
        title: result.msg,
        duration: 2000,
        icon: 'none'
      });
    }
  },

  //扫码
  scan: function () {
    wx.scanCode({
      success: (res) => {
        console.log("扫码结果");
        console.log(res);
        const scene = decodeURIComponent(res.path.split("=")[1]);
        console.log(scene);
       
        wx.navigateTo({
          url: "/"+res.path,
        })
        // wx.switchTab({
        //   url: "/pages/register/index"  // "/"+res.path
        // })
      },
      fail: (res) => {
        wx.showToast({
          title: 'fail',
          icon: 'none',
          duration: 1000
        })
        console.log(res);
      }
    })  
  },

  onShow: function () {
    wx.hideHomeButton()
  }
})